#此脚本在物理主机执行，进入容器执行elk0.sh脚本
#elk0.sh脚本映射在docker 容器的路径
path=/root/code/elk/elk0.sh
type=$1
action=$2
password=xieqihui                 
es_password=elastic
all_node="
master
slave"

task() {
  node=$1
  nodeName=$(echo $password | su - root -c "docker ps | grep $node | awk '{print(\$2)}'")
  echo
  # 启动容器
  if [ ! $nodeName ]; then
    echo $password | su - root -c "docker start $node"
  fi
  # 进入容器启动es集群
  echo $password | su - root -c "docker exec -i $node /bin/bash -c \"sh $path $type $action $node\""
}

if [ $type = "es" ]; then
  for n in ${all_node}; do
    task $n
  done
else
  sh /home/xieqihui/code/elk/elk0.sh $type $action
fi
